package com.techindata.cacheredis;

import java.util.Set;

import com.google.common.collect.Sets;
import org.apache.log4j.Logger;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

/**
 * @author jixiang
 * 
 *         Redis 模糊查询
 * 
 * **/
public class CacheScan {
	static Logger logger = Logger.getLogger(CacheScan.class);

	/**
	 * @param keys
	 *            匹配规则
	 * 
	 * @return Set<String> 返回String的Set的集合
	 * */
	public static Set<String> getResult(String keys) {
		JedisPool pool = RedisConnectionPool.getPool();
		try {
			Jedis jedis = pool.getResource();
            Set<String> setKey = jedis.smembers(keys);
            if(setKey == null || setKey.isEmpty()) {
                setKey = jedis.keys(keys);
            }
			RedisConnectionPool.returnResource(pool, jedis);
            return setKey;
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
            return Sets.newHashSet();
        }
	}

}
